import 'package:flutter/material.dart';

class HomeShopList extends StatelessWidget {
  const HomeShopList({super.key, required this.goodsList});

  final List goodsList;

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      shrinkWrap: true, //防止子组件超出屏幕
      physics: const NeverScrollableScrollPhysics(), //禁止滑动
      itemBuilder: (BuildContext context, int index) {
        Map item = goodsList[index]; //获取商品信息
        return Container(
            padding: const EdgeInsets.only(top: 10, bottom: 10),
            height: 120,
            color: Colors.white,
            child: Container(
              padding: const EdgeInsets.all(10),
              child: Row(
                children: [
                  //商品图片
                  Image.network("${item['goods_image']}",
                      width: 100, height: 120, fit: BoxFit.contain),
                  //商品名称
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "${item['goods_name']}",
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                        ),
                        Text(
                          "已售${item['goods_sales']}件",
                          style: const TextStyle(color: Colors.grey),
                        ),
                        Expanded(
                            child: Row(
                          children: [
                            Text(
                              "¥${item['goods_price_min']}",
                              style: const TextStyle(color: Colors.red),
                            ),
                            Container(
                              margin: const EdgeInsets.only(left: 10),
                              child: Text(
                                "¥${item['line_price_max']}",
                                style: const TextStyle(
                                    color: Colors.grey,
                                    decoration: TextDecoration.lineThrough),
                              ),
                            )
                          ],
                        ))
                      ],
                    ),
                  )
                ],
              ),
            ));
      },

      //分割线
      separatorBuilder: (BuildContext context, int index) {
        return Container(
            height: 10, color: const Color.fromARGB(255, 224, 221, 221));
      },
      itemCount: goodsList.length,
    );
  }
}
